package yunjiao.javatutorials.designpatterns.combinator;

import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;
import java.util.function.Function;

/**
 * {@link After} 示例
 *
 * @author yangyunjiao
 */
@Slf4j
public class AfterExample {
    void demo() {
        log.info("---------------------------------");
        log.info("Starting AFTER combinator demo...");
        log.info("---------------------------------");

        Function<BigDecimal, String> addTaxDecorated =
                After.decorate(this::addTax, this::after);

        String result = addTaxDecorated.apply(new BigDecimal("1000"));

        log.info("Done - Result is {}", result);
    }

    private String addTax(BigDecimal amount) {
        log.info("Adding heavy taxes to poor citizen...");
        return "$" + amount.multiply(new BigDecimal("1.22"));
    }

    private void after(BigDecimal argument, String result) {
        log.info("AFTER: Argument is {} Result is {}", argument, result);
    }
}
